import { types, unprotect } from "mobx-state-tree";
import dayjs from "dayjs";
import { array } from "mobx-state-tree/dist/internal";

// type DataSourceType = {
//   id: React.Key;
//   title?: string;
//   decs?: string;
//   state?: string;
//   created_at?: string;
//   update_at?: string;
//   children?: DataSourceType[];
// };

const defaultData = [
  {
    id: "1",
    title: "活动名称一",
    decs: "这个活动真好玩",
    state: "open",
    created_at: "2023-04-23 11:06:32",
    update_at: "1590486176000",
  },
  {
    id: "2",
    title: "活动名称二",
    decs: "这个活动真好玩",
    state: "closed",
    created_at: "2023-04-23 11:10:41",
    update_at: "1590481162000",
  },
];

export const Form = types
  .model("Form")
  .props({
    data: types.string,
  })
  .actions((self) => ({
    // 方法
    changeProps(values: any) {
      console.log("修改成功", values);
      self.data = JSON.stringify(values);
    },
  }));

export const form = Form.create({
  data: JSON.stringify(defaultData),
});

//解除安全模式   可以不用专门写修改props方法修改props值
unprotect(form);
